/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFFornecedores.java
 *
 * Created on 19/09/2012, 21:44:08
 */

package ecommercial;

import ecommercial.Classes.ClassConecta;
import ecommercial.Classes.ComboItem;
import ecommercial.Classes.Fornecedores;
import ecommercial.Classes.Funcoes;
import ecommercial.Classes.TipoFornecedores;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author vitiazze
 */
public class jFFornecedores extends javax.swing.JDialog {

    /** Creates new form jFFornecedores */
    public jFFornecedores() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        buscarjButton = new javax.swing.JButton();
        novojButton = new javax.swing.JButton();
        editarjButton = new javax.swing.JButton();
        salvarjButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        alterarjButton = new javax.swing.JButton();
        excluirjButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        sairjButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        gradeFornecedorjTable = new javax.swing.JTable();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tipoFornecedorjComboBox = new javax.swing.JComboBox();
        situacaojComboBox = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        datCadastrojFormattedTextField = new javax.swing.JFormattedTextField();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        obsjTextArea = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        cadastraTipoFornecedorjButton = new javax.swing.JButton();
        atualizaTipoFornecedorjButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ecommercial.EcommercialApp.class).getContext().getResourceMap(jFFornecedores.class);
        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        buscarjButton.setBackground(resourceMap.getColor("buscarjButton.background")); // NOI18N
        buscarjButton.setIcon(resourceMap.getIcon("buscarjButton.icon")); // NOI18N
        buscarjButton.setText(resourceMap.getString("buscarjButton.text")); // NOI18N
        buscarjButton.setFocusable(false);
        buscarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buscarjButton.setName("buscarjButton"); // NOI18N
        buscarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buscarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(buscarjButton);

        novojButton.setBackground(resourceMap.getColor("novojButton.background")); // NOI18N
        novojButton.setIcon(resourceMap.getIcon("novojButton.icon")); // NOI18N
        novojButton.setText(resourceMap.getString("novojButton.text")); // NOI18N
        novojButton.setFocusable(false);
        novojButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        novojButton.setName("novojButton"); // NOI18N
        novojButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        novojButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novojButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(novojButton);

        editarjButton.setBackground(resourceMap.getColor("editarjButton.background")); // NOI18N
        editarjButton.setIcon(resourceMap.getIcon("editarjButton.icon")); // NOI18N
        editarjButton.setText(resourceMap.getString("editarjButton.text")); // NOI18N
        editarjButton.setFocusable(false);
        editarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editarjButton.setName("editarjButton"); // NOI18N
        editarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(editarjButton);

        salvarjButton.setBackground(resourceMap.getColor("salvarjButton.background")); // NOI18N
        salvarjButton.setIcon(resourceMap.getIcon("salvarjButton.icon")); // NOI18N
        salvarjButton.setText(resourceMap.getString("salvarjButton.text")); // NOI18N
        salvarjButton.setFocusable(false);
        salvarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvarjButton.setName("salvarjButton"); // NOI18N
        salvarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salvarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(salvarjButton);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        alterarjButton.setBackground(resourceMap.getColor("alterarjButton.background")); // NOI18N
        alterarjButton.setIcon(resourceMap.getIcon("alterarjButton.icon")); // NOI18N
        alterarjButton.setText(resourceMap.getString("alterarjButton.text")); // NOI18N
        alterarjButton.setFocusable(false);
        alterarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        alterarjButton.setName("alterarjButton"); // NOI18N
        alterarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        alterarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alterarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(alterarjButton);

        excluirjButton.setBackground(resourceMap.getColor("excluirjButton.background")); // NOI18N
        excluirjButton.setIcon(resourceMap.getIcon("excluirjButton.icon")); // NOI18N
        excluirjButton.setText(resourceMap.getString("excluirjButton.text")); // NOI18N
        excluirjButton.setFocusable(false);
        excluirjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        excluirjButton.setName("excluirjButton"); // NOI18N
        excluirjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        excluirjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(excluirjButton);

        jSeparator2.setName("jSeparator2"); // NOI18N
        jToolBar1.add(jSeparator2);

        sairjButton.setBackground(resourceMap.getColor("sairjButton.background")); // NOI18N
        sairjButton.setIcon(resourceMap.getIcon("sairjButton.icon")); // NOI18N
        sairjButton.setText(resourceMap.getString("sairjButton.text")); // NOI18N
        sairjButton.setFocusable(false);
        sairjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sairjButton.setName("sairjButton"); // NOI18N
        sairjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sairjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(sairjButton);

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel2.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel2.border.titleColor"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        gradeFornecedorjTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "#Id", "Fornecedor", "Tipo de Fornecedor", "Situação", "Data Cadastro"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gradeFornecedorjTable.setName("gradeFornecedorjTable"); // NOI18N
        gradeFornecedorjTable.getTableHeader().setReorderingAllowed(false);
        gradeFornecedorjTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gradeFornecedorjTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(gradeFornecedorjTable);
        gradeFornecedorjTable.getColumnModel().getColumn(0).setResizable(false);
        gradeFornecedorjTable.getColumnModel().getColumn(0).setPreferredWidth(30);
        gradeFornecedorjTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("gradeFornecedorjTable.columnModel.title0")); // NOI18N
        gradeFornecedorjTable.getColumnModel().getColumn(1).setResizable(false);
        gradeFornecedorjTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        gradeFornecedorjTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("gradeFornecedorjTable.columnModel.title1")); // NOI18N
        gradeFornecedorjTable.getColumnModel().getColumn(2).setResizable(false);
        gradeFornecedorjTable.getColumnModel().getColumn(2).setPreferredWidth(80);
        gradeFornecedorjTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("gradeFornecedorjTable.columnModel.title2")); // NOI18N
        gradeFornecedorjTable.getColumnModel().getColumn(3).setResizable(false);
        gradeFornecedorjTable.getColumnModel().getColumn(3).setPreferredWidth(30);
        gradeFornecedorjTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("gradeFornecedorjTable.columnModel.title3")); // NOI18N
        gradeFornecedorjTable.getColumnModel().getColumn(4).setResizable(false);
        gradeFornecedorjTable.getColumnModel().getColumn(4).setPreferredWidth(50);
        gradeFornecedorjTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("gradeFornecedorjTable.columnModel.title4")); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 547, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.setForeground(resourceMap.getColor("jTabbedPane1.foreground")); // NOI18N
        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        tipoFornecedorjComboBox.setName("tipoFornecedorjComboBox"); // NOI18N

        situacaojComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ATIVO", "INATIVO" }));
        situacaojComboBox.setName("situacaojComboBox"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        try {
            datCadastrojFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        datCadastrojFormattedTextField.setName("datCadastrojFormattedTextField"); // NOI18N

        jPanel4.setBackground(resourceMap.getColor("jPanel4.background")); // NOI18N
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel4.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel4.border.titleColor"))); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        obsjTextArea.setColumns(20);
        obsjTextArea.setRows(5);
        obsjTextArea.setName("obsjTextArea"); // NOI18N
        obsjTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                obsjTextAreaKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(obsjTextArea);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        cadastraTipoFornecedorjButton.setIcon(resourceMap.getIcon("cadastraTipoFornecedorjButton.icon")); // NOI18N
        cadastraTipoFornecedorjButton.setText(resourceMap.getString("cadastraTipoFornecedorjButton.text")); // NOI18N
        cadastraTipoFornecedorjButton.setToolTipText(resourceMap.getString("cadastraTipoFornecedorjButton.toolTipText")); // NOI18N
        cadastraTipoFornecedorjButton.setContentAreaFilled(false);
        cadastraTipoFornecedorjButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cadastraTipoFornecedorjButton.setName("cadastraTipoFornecedorjButton"); // NOI18N
        cadastraTipoFornecedorjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastraTipoFornecedorjButtonActionPerformed(evt);
            }
        });

        atualizaTipoFornecedorjButton.setIcon(resourceMap.getIcon("atualizaTipoFornecedorjButton.icon")); // NOI18N
        atualizaTipoFornecedorjButton.setText(resourceMap.getString("atualizaTipoFornecedorjButton.text")); // NOI18N
        atualizaTipoFornecedorjButton.setContentAreaFilled(false);
        atualizaTipoFornecedorjButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        atualizaTipoFornecedorjButton.setName("atualizaTipoFornecedorjButton"); // NOI18N
        atualizaTipoFornecedorjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaTipoFornecedorjButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tipoFornecedorjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cadastraTipoFornecedorjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(atualizaTipoFornecedorjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(situacaojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(datCadastrojFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {datCadastrojFormattedTextField, situacaojComboBox, tipoFornecedorjComboBox});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tipoFornecedorjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cadastraTipoFornecedorjButton)))
                    .addComponent(atualizaTipoFornecedorjButton)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(situacaojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(datCadastrojFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 599, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public ClassConecta conexao = new ClassConecta();

    int cod_pessoas_fornecedores; //recebe cod pessoa para usar no cod_fornecedores

    ComboItem tipoFornecedor;


    public void getGrandeFornecedores() throws ParseException{
       //Consultar Fornecedores
        Fornecedores oFornecedor = new Fornecedores();

        ResultSet resultSet = null;

        String[] colunasTabela = new String[]{"Id#", "Fornecedor", "Tipo Fornecedor", "Situação", "Data Cadastro"};
        DefaultTableModel modeloTabela = new DefaultTableModel(null, colunasTabela) {

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };
        gradeFornecedorjTable.setModel(modeloTabela);
        gradeFornecedorjTable.getColumnModel().getColumn(0).setPreferredWidth(30);
        gradeFornecedorjTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        gradeFornecedorjTable.getColumnModel().getColumn(2).setPreferredWidth(80);
        gradeFornecedorjTable.getColumnModel().getColumn(3).setPreferredWidth(30);
        gradeFornecedorjTable.getColumnModel().getColumn(4).setPreferredWidth(50);

try {
            oFornecedor.setCod_pessoa(cod_pessoas_fornecedores);

            resultSet = oFornecedor.getConsultar();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Fornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                //Formatar data
                Date abertura = resultSet.getDate("DAT_CADASTRO");

                String dat_Cadastro = null;
                if (abertura != null){
                SimpleDateFormat formatoDataLanc = new SimpleDateFormat("dd/MM/yyyy");
                dat_Cadastro = formatoDataLanc.format(abertura);
                }else{
                dat_Cadastro = "";
                }
                //Fim formatação

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_PESSOA")),
                    resultSet.getString("PESSOA"),
                    resultSet.getString("COD_TIPO_FORNECEDOR"),
                    resultSet.getString("SITUACAO"),
                    dat_Cadastro
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(Fornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }

           }


    public void getFieldFornecedores(int cod_pessoas_fornecedores) throws ParseException, SQLException{

        Fornecedores oFornecedor = new Fornecedores();
        ResultSet rs = null;
        oFornecedor.setCod_pessoa(cod_pessoas_fornecedores);


            rs = oFornecedor.getConsultar();
            rs.next();

            //Pegar campos
            tipoFornecedorjComboBox.setSelectedItem(rs.getString("TIPO_FORNECEDOR"));
            situacaojComboBox.setSelectedItem(rs.getString("SITUACAO"));
            datCadastrojFormattedTextField.setValue(Funcoes.getDataFormat(rs.getDate("DAT_CADASTRO")));
            obsjTextArea.setText(rs.getString("OBS"));

        }

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        salvarjButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        novojButton.setEnabled(true);

        try {
            
            datCadastrojFormattedTextField.setText(Funcoes.getNowBR());
        } catch (ParseException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }


        buscarjButtonActionPerformed(null);
        atualizaTipoFornecedorjButtonActionPerformed(null);

    }//GEN-LAST:event_formWindowOpened

    private void sairjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairjButtonActionPerformed
        // TODO add your handling code here:
        if (!novojButton.isEnabled()){
                Object[] options = {"Sim", "Não"};
                int sd = JOptionPane.showOptionDialog(null, "Deseja realmente SAIR?", "Confirmação do Sistema!", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
                if (sd != 0) {
                    return;
                }

                this.dispose();

            }else{

                this.dispose();

            }
    }//GEN-LAST:event_sairjButtonActionPerformed

    private void obsjTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_obsjTextAreaKeyTyped
        // TODO add your handling code here:
        obsjTextArea.setLineWrap(true);
        obsjTextArea.setWrapStyleWord(true);
    }//GEN-LAST:event_obsjTextAreaKeyTyped

    private void novojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novojButtonActionPerformed
        // TODO add your handling code here:
        novojButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        buscarjButton.setEnabled(true);
        salvarjButton.setEnabled(true);
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFEstados.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_novojButtonActionPerformed

    private void salvarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarjButtonActionPerformed
        // TODO add your handling code here:
            salvarjButton.setEnabled(false);
            alterarjButton.setEnabled(false);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);
            editarjButton.setEnabled(true);

            Fornecedores oFornecedor = new Fornecedores();

            tipoFornecedor = (ComboItem) tipoFornecedorjComboBox.getSelectedItem();

        try {

            oFornecedor.setCod_pessoa(cod_pessoas_fornecedores);

            oFornecedor.setDat_cadastro(Funcoes.getDataFormatBR(datCadastrojFormattedTextField.getText()));
            oFornecedor.setCod_Tipo_fornecedor(tipoFornecedor.getId());
            oFornecedor.setSituacao(situacaojComboBox.getSelectedItem().toString());
            oFornecedor.setObs(obsjTextArea.getText());
            oFornecedor.setCadastrar();

        } catch (ParseException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
        } catch (SQLException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            getGrandeFornecedores();
        } catch (ParseException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_salvarjButtonActionPerformed

    private void buscarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            getGrandeFornecedores();
        } catch (ParseException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buscarjButtonActionPerformed

    private void alterarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alterarjButtonActionPerformed
        // TODO add your handling code here:
            alterarjButton.setEnabled(false);
            editarjButton.setEnabled(true);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);


            Fornecedores oFornecedor = new Fornecedores();

            tipoFornecedor = (ComboItem) tipoFornecedorjComboBox.getSelectedItem();

             try {

            oFornecedor.setCod_pessoa(cod_pessoas_fornecedores);

            oFornecedor.setDat_cadastro(Funcoes.getDataFormatBR(datCadastrojFormattedTextField.getText()));
            oFornecedor.setCod_Tipo_fornecedor(tipoFornecedor.getId());
            oFornecedor.setSituacao(situacaojComboBox.getSelectedItem().toString());
            oFornecedor.setObs(obsjTextArea.getText());
            oFornecedor.setAlterar(conexao);

        } catch (ParseException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
        } catch (SQLException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            getGrandeFornecedores();
        } catch (ParseException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_alterarjButtonActionPerformed

    private void editarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarjButtonActionPerformed
        // TODO add your handling code here:
            novojButton.setEnabled(false);
            salvarjButton.setEnabled(false);
            editarjButton.setEnabled(false);
            alterarjButton.setEnabled(true);
            excluirjButton.setEnabled(true);
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_editarjButtonActionPerformed

    private void gradeFornecedorjTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gradeFornecedorjTableMouseClicked
        // TODO add your handling code here:
        editarjButton.setEnabled(true);
            cod_pessoas_fornecedores = Integer.parseInt(gradeFornecedorjTable.getValueAt(gradeFornecedorjTable.getSelectedRow(), 0).toString());
            if (cod_pessoas_fornecedores == 0) {
                return;
            }
        try {
            getFieldFornecedores(cod_pessoas_fornecedores);
        } catch (ParseException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(jFFornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_gradeFornecedorjTableMouseClicked

    private void excluirjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirjButtonActionPerformed
        // TODO add your handling code here:
        Object[] options = {"Sim", "Não"};
        int sd =
                JOptionPane.showOptionDialog(null, "Deseja realmente EXCLUIR esse registro?", "Confirmação!", JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[0]);

        if (sd != 0) {
            return;
        }
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(true);
        excluirjButton.setEnabled(false);
        novojButton.setEnabled(true);

        Fornecedores oFornecedor = new Fornecedores();
        oFornecedor.setCod_pessoa(cod_pessoas_fornecedores);
        oFornecedor.setExcluir(conexao);
        try {
            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
        } catch (SQLException ex) {
            Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            getGrandeFornecedores();
        } catch (ParseException ex) {
            Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_excluirjButtonActionPerformed

    private void cadastraTipoFornecedorjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastraTipoFornecedorjButtonActionPerformed
        // TODO add your handling code here:
        jFTipoFornecedor oFormTipoFornecedor = new jFTipoFornecedor();

        oFormTipoFornecedor.setTitle("Tipo Fornecedores");
        oFormTipoFornecedor.setDefaultCloseOperation(jFTipoFornecedor.DO_NOTHING_ON_CLOSE);
        oFormTipoFornecedor.pack();
        oFormTipoFornecedor.setModal(true);
        oFormTipoFornecedor.setLocationRelativeTo(null);
        oFormTipoFornecedor.setVisible(true);
    }//GEN-LAST:event_cadastraTipoFornecedorjButtonActionPerformed

    private void atualizaTipoFornecedorjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaTipoFornecedorjButtonActionPerformed
        // TODO add your handling code here:
        try {
            // TODO add your handling code here:
            TipoFornecedores oTipoFornecedor = new TipoFornecedores();
            ResultSet rs = null;
            rs = oTipoFornecedor.getConsultar();
            tipoFornecedorjComboBox.removeAllItems();
            while (rs.next()) {
                tipoFornecedorjComboBox.addItem(new ComboItem(rs.getInt("COD_TIPO_FORNECEDOR"), rs.getString("TIPO_FORNECEDOR")));
            }
            tipoFornecedorjComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(jFTipoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_atualizaTipoFornecedorjButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFFornecedores().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton alterarjButton;
    private javax.swing.JButton atualizaTipoFornecedorjButton;
    private javax.swing.JButton buscarjButton;
    private javax.swing.JButton cadastraTipoFornecedorjButton;
    private javax.swing.JFormattedTextField datCadastrojFormattedTextField;
    private javax.swing.JButton editarjButton;
    private javax.swing.JButton excluirjButton;
    private javax.swing.JTable gradeFornecedorjTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton novojButton;
    private javax.swing.JTextArea obsjTextArea;
    private javax.swing.JButton sairjButton;
    private javax.swing.JButton salvarjButton;
    private javax.swing.JComboBox situacaojComboBox;
    private javax.swing.JComboBox tipoFornecedorjComboBox;
    // End of variables declaration//GEN-END:variables

}
